import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class GetURLContent {

    public void saveHTML(String rootUrl) {

        URL url;

        try {

            url = new URL(rootUrl);
            URLConnection conn = url.openConnection();


            BufferedReader br = new BufferedReader(new InputStreamReader(
                    conn.getInputStream()));

            String inputLine;

            String name = rootUrl.replace("http://", "").replace(".", "_").replace("/","_");
            String fileName = "C:\\GLBaseCampRepo\\PageSaver\\src\\main\\resources\\" + name + ".html";
            File file = new File(fileName);

            if (!file.exists()) {
                file.createNewFile();
            }


            FileWriter fw = new FileWriter(file.getAbsoluteFile());
            BufferedWriter bw = new BufferedWriter(fw);

            while ((inputLine = br.readLine()) != null) {
                bw.write(inputLine);
            }

            bw.close();
            br.close();



        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
